package com.tengju.bff.interfaces.covercharge.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tengju.bff.interfaces.covercharge.entity.po.ServiceContractTemplate;
import com.tengju.bff.interfaces.covercharge.entity.vo.contract.SignContractTemplateReqVo;
import com.tengju.bff.interfaces.covercharge.entity.vo.contract.SignContractTemplateResVo;
import com.tengju.bff.interfaces.covercharge.mapper.ServiceContractTemplateMapper;
import com.tengju.bff.interfaces.covercharge.service.IServiceContractTemplateService;
import com.tengju.bff.interfaces.covercharge.util.BeanMapperUtils;
import com.tengju.bff.interfaces.covercharge.util.DateTimeUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @author liang_shi
 * @date 2020/7/14 10:47
 * @description 合同模板服务实现
 */
@Slf4j
@Service
public class ServiceContractTemplateServiceImpl extends ServiceImpl<ServiceContractTemplateMapper, ServiceContractTemplate> implements IServiceContractTemplateService {

    @Autowired
    private ServiceContractTemplateMapper contractTemplateMapper;

    @Override
    public SignContractTemplateResVo queryContractTemplate(SignContractTemplateReqVo reqVo) {
        ServiceContractTemplate queryTemplate = new ServiceContractTemplate();
        queryTemplate.setContractType(reqVo.getContractType());
        log.info("查询模板信息,reqVo:{}", reqVo);
        ServiceContractTemplate contractTemplate = contractTemplateMapper.selectOne(new QueryWrapper<>(queryTemplate));
        if (Objects.isNull(contractTemplate)) {
            return null;
        }
        SignContractTemplateResVo resVo = BeanMapperUtils.map(contractTemplate, SignContractTemplateResVo.class);
        resVo.setCreateTime(DateTimeUtils.parseDateAsString(contractTemplate.getCreateTime(), DateTimeUtils.DEFAULT_DATE_TIME_FORMAT));
        resVo.setUpdateTime(DateTimeUtils.parseDateAsString(contractTemplate.getUpdateTime(), DateTimeUtils.DEFAULT_DATE_TIME_FORMAT));
        log.info("获取到模板信息:{}", resVo);
        return resVo;
    }

}
